package blackeagle.ems;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import se.oru.informatik.StringHelper;

/**
 * Manages logging
 */
public final class Logger {
    /**
     * The log file to which messages will be saved.
     */
    private static final String logFile = "blackeagleems.log";
    
    private Logger(){}
    
    /**
     * Logs a given message. A timestamp is added in front of the message.
     * @param message the message.
     */
    public static void log(String message){
        Calendar cal  = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        
        String logMsg = StringHelper.sprintf("[#] #", sdf.format(cal.getTime()), message);
        
        try{
            FileWriter fw = new FileWriter(Logger.logFile);
            BufferedWriter bw = new BufferedWriter(fw);
            bw.write(logMsg);
        
            bw.close();
        }catch(Exception e){}
    }
}
